package com.vtest.quartz.task.needlecard;

import com.vtest.quartz.domain.needle.BIDNeedleEntity;
import com.vtest.quartz.domain.needle.STHNeedleEntity;
import com.vtest.quartz.service.needle.NeedleService;
import com.vtest.quartz.utils.MailHelper;
import com.vtest.quartz.utils.excel.ExcelUtil;
import com.vtest.quartz.utils.others.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.File;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * @program: Quartz
 * @author: tiger
 * @create: 2025-07-18 11:10
 * @Description :
 */
@Slf4j
@Component("STHReport")
public class STHReport {

    @Autowired
    private NeedleService needleService;

    public void sendNeedleReport() {
        log.debug("[STH 针卡报表] 任务开始执行");
        LocalDate date = LocalDate.now();
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String time = date.format(dateTimeFormatter);

        List<STHNeedleEntity> sthNeedleInfoList = needleService.findSTHNeedleInfo(time);

        ExcelUtil<STHNeedleEntity> util = new ExcelUtil<>(STHNeedleEntity.class);

        util.exportExcel(sthNeedleInfoList, "STH_Probe_Card_" + time, StringUtils.EMPTY, true);

        File localFile = new File(util.downFile);
        if (localFile.exists()) {
            MailHelper helper = new MailHelper();
            helper.sendMail("zhiqiang.song@v-test.com.cn;yawu.li@v-test.com.cn;huaiju.zhao@v-test.com.cn;VT_PCR@v-test.com.cn;summer.zhang@v-test.com.cn"
                    , "ruhu.wang@v-test.com.cn", "STH报表", "STH报表", util.downFile);
        }
        log.debug("[STH 针卡报表] 邮件发送结束");


    }
}
